Skip to content

perf(server): bound OpenCode history hydration#4348

Open
nateEc wants to merge 2 commits into
pingdotgg:mainfrom
nateEc:codex/fix-3601-opencode-history-bounds
Open

perf(server): bound OpenCode history hydration#4348
nateEc wants to merge 2 commits into
pingdotgg:mainfrom
nateEc:codex/fix-3601-opencode-history-bounds

Conversation

@nateEc

@nateEc nateEc commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Closes #3601

Summary

  • cap routine OpenCode thread hydration at the latest 100 messages instead of materializing the full session
  • page older messages on demand when rollback needs more assistant turns
  • impose a 15-second per-page timeout and pass cancellation through to the SDK request
  • preserve rollback semantics across multiple history pages

Verification

  • ./node_modules/.bin/vp test run apps/server/src/provider/Layers/OpenCodeAdapter.test.ts (33 passed)
  • ./node_modules/.bin/vp run --filter t3 typecheck (passes; three unrelated existing Effect suggestions remain in orchestration/decider.ts)
  • targeted lint and formatting for the changed files

Note

Medium Risk
Changes how thread snapshots are built and how rollback resolves targets across paginated history; incorrect paging could mis-revert long threads, though behavior is covered by new adapter tests.

Overview
OpenCode thread hydration is capped so routine reads no longer pull the entire session history from the SDK.

readThread now loads a single page of 100 messages via session.messages (limit / optional before) instead of unbounded history. readThread therefore exposes at most the 100 most recent assistant turns—a deliberate behavior change for performance.

rollbackThread uses readOpenCodeMessagesForRollback to walk older pages only until it has enough assistant messages to pick the revert target, with deduplication and extra pagination when a full page overlaps the previous cursor.

Each history page goes through readOpenCodeMessagePage: 15s timeout, AbortSignal passed into the SDK call, and a clear timeout error on stall. runOpenCodeSdk now takes a callback (signal) => Promise<...> so cancellation can reach the client.

Tests extend the runtime mock for paged messages, hang/abort, and overlap, and add coverage for read bounds, rollback paging, overlap continuation, and timeout behavior.

Reviewed by Cursor Bugbot for commit 8e48e6d. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Bound OpenCode history hydration to paginated reads with a 15s timeout

  • readThread now reads only the latest 100 messages (one page) instead of the full session history, with a 15-second timeout per request.
  • rollbackThread uses a new readOpenCodeMessagesForRollback helper that pages backwards through history only as far as needed to locate the target assistant message, deduplicating overlapping page boundaries.
  • runOpenCodeSdk in opencodeRuntime.ts now passes an AbortSignal to the SDK callback so timed-out reads are cleanly cancelled.
  • New tests in OpenCodeAdapter.test.ts cover page bounding, paginated rollback, overlapping-page deduplication, and timeout/abort behaviour.
  • Behavioral Change: readThread no longer returns messages beyond the most recent 100; sessions with long histories will see a truncated turn list.

Macroscope summarized 8e48e6d.

- Limit routine OpenCode thread reads to the latest 100 messages.
- Page older messages only when rollback requires additional turns.
- Abort and surface session history reads that exceed 15 seconds.
- Add focused paging, timeout, and cancellation coverage.
@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 693168b9-b742-4e80-ace1-cdf65e2b8c8d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 335f2f6. Configure here.

Comment thread apps/server/src/provider/Layers/OpenCodeAdapter.ts
@macroscopeapp

macroscopeapp Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Performance optimization that bounds OpenCode history hydration to 100 messages with a 15-second timeout, preventing unbounded fetching. Changes are well-tested with comprehensive pagination and timeout test cases. No new features or schema changes—purely defensive performance improvement.

You can customize Macroscope's approvability policy. Learn more.

- Determine history exhaustion from the raw API page before deduplication.
- Advance pagination from the raw oldest message boundary.
- Add rollback coverage for full pages that overlap the preceding page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenCode provider hangs opening/resuming a large thread — readThread pulls full session history unpaginated, no timeout

1 participant